package com.bw.shop.fg

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log

import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager

import com.bumptech.glide.Glide
import com.bw.basecommon.BaseFragment
import com.bw.shop.R
import com.bw.shop.XQActivity
import com.bw.shop.adapter.CateAdapter
import com.bw.shop.adapter.ZCDCAdapter
import com.bw.shop.entity.ZCDCEntity
import com.bw.shop.databinding.FragmentShopBinding
import com.bw.shop.entity.cateEntity
import com.therouter.TheRouter

import com.youth.banner.loader.ImageLoader
import kotlin.math.log


class ShopFragment : BaseFragment<FragmentShopBinding>() {



    private lateinit var zcdcAdapter: ZCDCAdapter

    private  val ZCDCList: ArrayList<ZCDCEntity> = arrayListOf()
    private  val BKCXList: ArrayList<ZCDCEntity> = arrayListOf()
    private  val TYPJList: ArrayList<ZCDCEntity> = arrayListOf()
    private  val WNYXList: ArrayList<ZCDCEntity> = arrayListOf()





    override fun initView() {

        for ( a in 0..9){

            ZCDCList.add(ZCDCEntity("增程电池A","品牌电池 续航保障","￥4509","￥3909.00",R.drawable.zcdctwo))

        }



        zcdcAdapter= ZCDCAdapter()

        binding.rvzc.adapter=zcdcAdapter
        binding.rvzc.layoutManager= LinearLayoutManager(requireActivity(), LinearLayoutManager.HORIZONTAL,false)

        zcdcAdapter.data.addAll(ZCDCList)
        zcdcAdapter.notifyDataSetChanged()


        for ( a in 0..9){

            BKCXList.add(ZCDCEntity("校园短途萌妹电动车","都市版 认证上牌","￥4509","￥3909.00",R.drawable.bkcxtwo))

        }

        zcdcAdapter= ZCDCAdapter()

        binding.rvbk.adapter=zcdcAdapter
        binding.rvbk.layoutManager= LinearLayoutManager(requireActivity(), LinearLayoutManager.HORIZONTAL,false)

        zcdcAdapter.data.addAll(BKCXList)
        zcdcAdapter.notifyDataSetChanged()

        for ( a in 0..9){

            TYPJList.add(ZCDCEntity("头盔","强硬耐用 轻盈透气","￥29.00","￥19.00",R.drawable.typjtwo))

        }

        zcdcAdapter= ZCDCAdapter()

        binding.rvty.adapter=zcdcAdapter
        binding.rvty.layoutManager= LinearLayoutManager(requireActivity(), LinearLayoutManager.HORIZONTAL,false)

        zcdcAdapter.data.addAll(TYPJList)
        zcdcAdapter.notifyDataSetChanged()

        for ( a in 0..9){

            WNYXList.add(ZCDCEntity("NQI大挡风","简约时尚","￥19.00","已售1000",R.drawable.wnyx))

        }

        zcdcAdapter= ZCDCAdapter()

        binding.rvyx.adapter=zcdcAdapter
        binding.rvyx.layoutManager= GridLayoutManager(requireActivity(),2)

        zcdcAdapter.data.addAll(WNYXList)
        zcdcAdapter.notifyDataSetChanged()






        binding.bkall.setOnClickListener {


            //TheRouter.build("/Shop/XQActivity").navigation()
            startActivity(Intent(requireActivity(), XQActivity::class.java))
            Log.i("ss", "initView: s")
        }

        val BannerList: ArrayList<String> = arrayListOf()


        BannerList.add("https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/homeNew/banner4-1124.jpg")
        BannerList.add("http://10.161.9.80:7015/banner/banner4.png")
        BannerList.add("http://10.161.9.80:7015/banner/banner6.png")


        binding.banner.apply {
            setImages(BannerList)
            setImageLoader(object : ImageLoader() {
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context != null && path != null) {
                        Glide.with(context).load(path as String).into(imageView!!)
                    }
                }
            })
            isAutoPlay(true)  // 开启自动轮播
            // 轮播间隔3秒
            start()
        }


    }

    override fun initData() {


    }

    override fun getLayoutID()=R.layout.fragment_shop
}